package yuhuibear.poat.object.bean;

import static org.junit.Assert.assertEquals;

import javax.sql.DataSource;

import org.junit.Test;

import yuhuibear.poat.object.mapEntity.DataBaseMapper;
import yuhuibear.poat.test.util.PoatTestSource;

/**
 * 
 * @author yuhuibear
 */
public class DataBaseMapperTest {

	public DataBaseMapperTest() {
	}

	/**
	 * Test of createTable method, of class DataBaseMapper.
	 */
	@Test
	public void testCreateTable_clear() throws Exception {
		DataSource ds = new PoatTestSource();
		PersistentClassLoader bsFactory = PersistentClassLoader.getInstance();
		int cnt = 0;
		cnt = cnt + bsFactory.scanPackage("yuhuibear.poat.test.entity");
		cnt = cnt + bsFactory.scanPackage("com.bgIntlgn.client.entity");
		DataBaseMapper instance = new DataBaseMapper(bsFactory.getAllStructs());
		int expResult = 120;
		int result = instance.createTable(ds.getConnection(), true);
		assertEquals(expResult, result);
	}

	@Test
	public void testCreateTable_noClear() throws Exception {
		int cnt = 0;
		DataSource ds = new PoatTestSource();
		PersistentClassLoader bsFactory = PersistentClassLoader.getInstance();
		cnt = cnt + bsFactory.scanPackage("com.bgIntlgn.client.entity");
		DataBaseMapper instance = new DataBaseMapper(bsFactory.getAllStructs());
		int expResult = 45;
		int result = instance.createTable(ds.getConnection(), false);
		assertEquals(expResult, result);

	}
}
